//Source file: I:\\ISS\\UNIT3\\JAVA PACKAGE\\edu\\nus\\iss\\t5\\jass\\controller\\JobResponseController.java

package edu.nus.iss.t5.jass.controller;

import edu.nus.iss.t5.jass.entity.JobResponse;
import edu.nus.iss.t5.jass.dao.JobResponseDAO;
import edu.nus.iss.t5.jass.entity.JobAdvertisement;
import edu.nus.iss.t5.jass.view.ListResponsePanel;
import edu.nus.iss.t5.jass.view.ResponseDetailsPanel;

import java.io.IOException;
import java.util.List;

/**
 * This is controll class for JobResponse. It invokes DAO to get Entity class, and 
 * call UI class to display the entity.
 */
public class JobResponseController 
{
   
   private JobResponseDAO theJobResponseDAO;
   private static JobResponseController instance;

   private ListResponsePanel listResponsePanel;
   private ResponseDetailsPanel responseDetailsPanel;



   /**
    * @throws IOException 
 * @roseuid 4CB1D853015F
    */
   private JobResponseController() throws IOException
   {
    try {
	theJobResponseDAO=new JobResponseDAO();
	} catch (IOException e) {
		
		e.printStackTrace();
	}
    
     listResponsePanel = new ListResponsePanel(this);
     responseDetailsPanel=new ResponseDetailsPanel(this);

   }
/**
 * Get Job Response Controller instance.
 * This class implements Singleton pattern to ensure that only one instance can be created.
 * @return Job Response Controller Instance
 */
   public  static JobResponseController getInstance()
   {
       if(instance == null)
       {
           synchronized(JobResponseController.class) {
             if (instance == null)
				try {
					instance = new JobResponseController();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
       }
       return instance;
   }

   /**
    * This function will invoke JobResponseDAO to get all job response to a specific 
    * job advertisement.
    * @param jobAdertisement Job Adervistsement object
    * @return List of Job Response to inputted Job Advertisement
    * @roseuid 4C512C2C032D
    */
   public List<JobResponse> getAllResponses(JobAdvertisement jobAdertisement)
   {
       List<JobResponse> jobResponseList=theJobResponseDAO.getResponsesByAdvert( jobAdertisement);
    
       return jobResponseList;
   }
   
   /**
    * This function invokes JobResponseDAO to retrive job response by the job 
    * response ID.
    * @param responseID
    * @return edu.nus.iss.t5.jass.entity.JobResponse
    * @roseuid 4C512C4001D3
    */
   public JobResponse getJobResponse(String responseID)
   {
       JobResponse jobResponse=this.theJobResponseDAO.getJobResponse(responseID);
       return jobResponse;
   }

   /**
    * Display Response List panel by specificed Job Advertisement.
    * @param jobAdvertisement the job advertisement object.
    */
   public void showResponseListPanel(JobAdvertisement jobAdvertisement)
   {
       List<JobResponse> responseList=this.getAllResponses(jobAdvertisement);

       listResponsePanel.ShowListResponses(responseList);
   }

/**
 * Display Job Response detail information based on the inputted Job Response entity.
 * @param jobResponse The job response entity.
 */
   public void showResposneDetailPanel(JobResponse jobResponse)
   {
       responseDetailsPanel.ShowResponseDetaill(jobResponse);
   }

}
